#{extends 'main.html' /}
#{set title:'Home' /}

<div>
    <h3>${post.subject}</h3>
</div>
<div class="row">
    <div class="col-md-2"></div>
    <div class="col-md-2"><a href="#"><span class="glyphicon glyphicon-eye-open" aria-hidden="true"></span></a>(${post.view_cnt})</div>
    <div class="col-md-2"><a href="@{Forum.voteup(post.id)}"><span class="glyphicon glyphicon-thumbs-up" aria-hidden="true"></span></a>(${post.voteup_cnt})</div>
    <div class="col-md-2"><a href="@{Forum.follow(post.id)}"><span class="glyphicon glyphicon-heart" aria-hidden="true"></span></a>(${post.follow_cnt})</div>
    <div class="col-md-2"><a href="@{Forum.favor(post.id)}"><span class="glyphicon glyphicon-bookmark" aria-hidden="true"></span></a>(${post.favorite_cnt})</div>
    <div class="col-md-2">分类：${post.board?post.board.name:"无"}</div>
    <div class="col-md-2">创建于：${post.created_at.format('yyyy-MM-dd')}</div>
</div>
<div>
    <blockquote>
        ${post.summary}
    </blockquote>
</div>
<div>
    ${post.content.raw()}
</div>

<div>
    #{list post.resources, as:"resource"}
    <img src="@{Resources.raw(resource.hash,'raw')}" style="max-width:100px;max-height:100px;"/>
    #{/list}
</div>


<div class="row">
    <ul class="list-group">
        #{list post.load_replies(), as:"reply"}
        <li class="list-group-item">${reply.user.nickname} @ ${reply.created_at}:${reply.content}
            <div>
                #{list reply.resources, as:"reply_res"}
                <img src="@{Resources.raw(reply_res.hash,'raw')}" style="max-width:100px;max-height:100px;"/>
                #{/list}
            </div>
            <form class="form " method="post" action="@{Forum.save_reply}" id="rereply_form">
                <input type="hidden" name="post_id" value="${post.id}"/>
                <input type="hidden" name="reply_id" value="${reply.id}"/>
                <div class="form-group">
                    <label for="content">回复</label>
                    <input name="content" type="text" class="form-control" id="content"></input>
                </div>
                <button type="submit" class="btn btn-default">回复</button>
            </form>
        </li>
        #{/list}
    </ul>
</div>
<div class="row">

    <div class="col-md-12">

        <form class="form " method="post" action="@{Forum.save_reply}" id="reply_form">
            <input type="hidden" name="post_id" value="${post.id}"/>
            <div class="form-group">
                <label for="content">回复</label>
                <textarea name="content" type="text" class="form-control" id="content"></textarea>
            </div>
            <button type="submit" class="btn btn-default">回复</button>
        </form>
    </div>

</div>
<div>
    <form action="@{Resources.file_upload}" class="dropzone" id="my-awesome-dropzone"></form>
</div>

#{set "moreScripts"}
<script>
    Dropzone.options.myAwesomeDropzone = {
        init: function () {
            this.on("success", function (file) {
                var obj = $.parseJSON(file.xhr.responseText);
                var input = $("<input>");
                input.attr("type", "hidden").attr("name", "attachs").attr("value", obj.datas.resource.id)
                $("#reply_form").append(input);
            });
        }
    };
</script>
#{/set}
